package reflect;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

public class Test2 {
    public static void main(String[] args) throws Exception {
        Class cls = Class.forName("reflect.Person");
        Object o = cls.newInstance();
        Method[] methods = cls.getMethods();
        for (int i=0;i< methods.length;i++){
            int m =methods[i].getModifiers();
            switch (m){
                case Modifier.PUBLIC:
                    if (methods[i].getName().contains("s") && methods[i].getParameterCount()==0){
                        System.out.println("调用方法："+methods[i].getName()+"()");
                        methods[i].invoke(o);
                    }
            }
        }


    }
}
